package org.xxpay.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.xxpay.core.entity.SysProvinceCode;
import org.xxpay.core.entity.SysProvinceCodeExample;
import org.xxpay.core.service.ISysProvinceCodeService;
import org.xxpay.service.dao.mapper.SysProvinceCodeMapper;

import java.util.List;


@Service
public class SysProvinceCodeServiceImpl implements ISysProvinceCodeService {

    @Autowired
    SysProvinceCodeMapper sysProvinceCodeMapper;

    @Override
    public int add(SysProvinceCode sysProvinceCode) {
        return sysProvinceCodeMapper.insertSelective(sysProvinceCode);
    }

    @Override
    public int update(SysProvinceCode sysProvinceCode) {
        return sysProvinceCodeMapper.updateByPrimaryKeySelective(sysProvinceCode);
    }

    @Override
    public SysProvinceCode find(SysProvinceCode sysProvinceCode) {
        return sysProvinceCodeMapper.selectByPrimaryKey(sysProvinceCode.getProvinceCode());
    }

    @Override
    public List<SysProvinceCode> select(SysProvinceCode sysProvinceCode) {
        SysProvinceCodeExample example = new SysProvinceCodeExample();
        SysProvinceCodeExample.Criteria criteria = example.createCriteria();
        setCriteria(criteria, sysProvinceCode);
        return sysProvinceCodeMapper.selectByExample(example);
    }

    void setCriteria(SysProvinceCodeExample.Criteria criteria, SysProvinceCode sysProvinceCode) {
        if(sysProvinceCode != null) {
            if(sysProvinceCode.getProvinceCode() != null) criteria.andProvinceCodeEqualTo(sysProvinceCode.getProvinceCode());
        }
    }
}
